<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../../value/value_en.php";
} else if($lang == "VN") {
	include "../../value/value_vn.php";
}
else {
	include "../../value/value_kr.php";
}
include '../../generallibraries/funcs.php';
include '../../operations/connection.php';	

$list["ac_customer.Email"]="ASC";
$list["ac_customer.CustomerName"]="ASC";
$list["ac_customer.Address"]="ASC";
$list["ac_customer.Phone"]="ASC";
$list["ac_customer.Fax"]="ASC";
$list["ac_customer.CreatedDate"]="DESC";
$str="ac_customer.CreatedDate";
$_SESSION['accsortn']=$str;
$_SESSION['accsort']=$list;
$page=1;
$rows_per_page = $_SESSION['accrows_page'] ;
$page_start = ( $page - 1 ) * $rows_per_page; 
$page_end = $page * $rows_per_page;
$co=0;
$hamsort=" where ac_customer.CustomerName like '%".$_REQUEST['search']."%' ORDER BY ".$str." ".$list[$str]."";
$sqlCustomer = generalFunctions::listCustomer("ac_customer.CustomerID, ac_customer.CustomerName, ac_customer.Address, ac_customer.Phone, ac_customer.Fax,ac_customer.Email",$hamsort);
$mangCustomer=mysql_query($sqlCustomer);
$number_of_page = ceil ( mysql_num_rows( $mangCustomer ) / $rows_per_page ); 
$_SESSION['checksoluong']=mysql_num_rows( $mangCustomer );
?>
<table class="cssTable" width="100%" >
	<thead>
		<!-- <tr><td colspan="6"><?php echo $sqlCustomer;?></td><tr>   -->
		<tr>
			<th scope="col"></th>
			<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.CustomerName',1);" ><?php echo $l_customername;?></a></th>
			<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.Address',1);" ><?php echo $l_address;?></a></th>
			<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.Phone',1);" ><?php echo $l_phone;?></a></th>
			<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.Fax',1);" ><?php echo $l_Fax;?></a></th>
			<th scope="col"><a onclick="sort(<?=$page?>,'ac_customer.Email',1);" ><?php echo $l_email;?></a></th>
		</tr>
	</thead>
	<tbody>
		<?php 
			if(mysql_num_rows($mangCustomer)>0){
				$i=0;
				while($row = mysql_fetch_array($mangCustomer)){
					if ( $i >= $page_start ){
					?>
						<tr>
									<td style="width: 10px"><div style="text-align:center"><input onclick="checkonly(this.id,document.accsetupcus.list,<?=$page?>);" type="checkbox" name="list" id="<?php echo 'checkcus'.$i?>" value="<?=$row[CustomerID]?>"/></div></td>
									<td style="width: 150px"><?php echo $row[CustomerName];?></td>
									<td><?php echo $row[Address];?></td>
									<td style="width: 80px"><?php echo $row[Phone];?></td>
									<td style="width: 80px"><?php echo $row[Fax];?></td>
									<td style="width: 80px"><?php echo $row[Email];?></td>
									</tr>
					<?php 
					}
					$i++;
					if ($i >= $page_end){ 
						break; 
					}
				}								
			}
		?>
		<tr>
			<td colspan="6" class="bt_td_main">
				<span style="background:#fff; padding:1px; display: inline-block;">
											
					<?php if ( $number_of_page > 1 ) 
					{ 
						if ($page==1)
							$p=2;
						else if ($page==$number_of_page)
							$p=$number_of_page-1;
						else $p=$page;
						if($page!=1){?>
							<a onclick="sort(1,'<?=$str?>',0);" ><span class='button_next'><?php echo "<<<";?></span> </a>
							<a onclick="sort(<?=($page-1)?>,'<?=$str?>',0);" ><span class='button_next'><?php echo "<<";?></span> </a>
						<?php  }
						else{
							echo "<span class='button_next'><<<</span> "; 
							echo "<span class='button_next'><<</span> ";
						}
						for ( $i = $p-1; $i <= $p+1; $i++ ) {	
								if ($i<=$number_of_page && $i>0)
								
									if ($i==$page){
										echo "<span class='button_next'><b>".$i."</b></span>"; 
									}else{
									?>
										<a onclick="sort(<?=$i?>,'<?=$str?>',0);" ><span class="button_next" style="color: #508e21;">
										<?php 
										echo $i;
										?>
										</span> </a>
										<?php 
									}
								?>
							
						<?php 
								}
							
							if($page!=$number_of_page){ ?>
								<a onclick="sort(<?=($page+1)?>,'<?=$str?>',0;"><span class='button_next'><?php echo ">>";?></span> </a>
								<a onclick="sort(<?=($number_of_page)?>,'<?=$str?>',0);" ><span class='button_next'><?php echo ">>>";?></span> </a>
							<?php }
							else{
								echo "<span class='button_next'>>></span> ";
								echo "<span class='button_next'>>>></span> ";
							}
						}
					
						
						?>
																			
				</span>
			</td>
		</tr>
	</tbody>
</table>
<?php mysql_close($connection);?>